﻿using System;
using System.Windows.Forms;
using DICOMViewer.Model;
using DICOMViewer.Utility;

namespace DICOMViewer
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
#if DEBUG
            txt_UserCode.Text = "13588734136";
#endif
        }

        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WinMessageUtility.WM_COPYDATA)
                //根据Message.Msg区分消息类型，ImportFromDLL.WM_COPYDATA为发送方定义的消息类型
            {
                CopyDataStruct copyData =
                    (CopyDataStruct) m.GetLParam(typeof (CopyDataStruct));
                var args = copyData.lpData.Split(' ');
                for (var i = 0; i < args.Length; i = i + 2)
                {
                    if (LoginInfo.Current != null)
                    {
                    }
                }
            }
            base.WndProc(ref m);
        }


        private void cb_cancel_Click(object sender, EventArgs e)
        {
            //关闭
            Close();
        }

        private void cb_login_Click(object sender, EventArgs e)
        {
            f_login();
        }


        private void txt_Password_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                e.Handled = true;
                f_login();
            }
        }

        private void f_login()
        {
            if (LoginUtility.Login(txt_UserCode.Text, txt_Password.Text))
            {
                MainForm mainform = new MainForm();
                mainform.Show();
                Hide();
            }
        }
    }
}